package com.znh.entity;

import com.znh.enums.PieceActionEnum;
import com.znh.enums.PieceInitLocationEnum;
import com.znh.enums.PiecePlayerEnum;

import java.awt.*;

/**
 * @version 1.0
 * @Author znh
 * @Date 2024/5/24 下午3:29
 * @注释 炮类
 */
public class Pao extends Piece {
    public Pao(int id, Point point, PiecePlayerEnum player, PieceInitLocationEnum initLocation) {
        super(id, "pao", point, player, initLocation, new StringBuilder().append("images/pao")
                .append(player == PiecePlayerEnum.RED ? "0" : "1").append(".png").toString());
    }

    @Override
    public boolean isMove(Point tp) {
        PieceActionEnum action = action(tp);
        //移动：是否走直线、当前位置到目标位置之间是否有棋子
        if (!GameRule.POINT_PIECE_MAP.containsKey(tp)) {
            return (action == PieceActionEnum.LINEX && countRoutePiece(tp, PieceActionEnum.LINEX) == 0)
                    || (action == PieceActionEnum.LINEY && countRoutePiece(tp, PieceActionEnum.LINEY) == 0);
        } else {
            //吃子：是否走直线、当前位置到目标位置之间是否有炮架
            return (action == PieceActionEnum.LINEX && countRoutePiece(tp, PieceActionEnum.LINEX) == 1)
                    || (action == PieceActionEnum.LINEY && countRoutePiece(tp, PieceActionEnum.LINEY) == 1);
        }
    }

    @Override
    public boolean simulateMove(Point tp) {
        return  isMove(tp)&&super.simulateMove(tp);
    }
}
